package com.zhaungjie.base.utils;

/**
 * 字符串工具类
 *
 * @author zhuangjie
 * @date 2023/12/30
 */
public class StringUtils {
    /**
     * 判断字符串为空
     *
     * @param str str
     * @return boolean
     */
    public static boolean isBlank(String str) {
        return str == null || "".equals(str.trim());
    }

    /**
     * trim特定字符串
     *
     * @param str      str
     * @param toRemove 删除
     * @return {@link String}
     */
    public static String trimSpecificString(String str, String toRemove) {
        str = trimBegin(str, toRemove);
        return trimEnd(str, toRemove);
    }

    public static String trimEnd(String str, String removeLastStr) {
        if (str == null || removeLastStr == null ) {
            return str;
        }
        while (str.endsWith(removeLastStr)) {
            str = str.substring(0, str.length() - removeLastStr.length());
        }
        return str;
    }
    public static String trimBegin(String str, String removeBeginStr) {
        // 如果字符串是null 或者 待移除字符串是null或空，直接返回原字符串
        if (str == null || removeBeginStr == null ) {
            return str;
        }
        // 当字符串以待移除的字符串开头时，移除之
        while (str.startsWith(removeBeginStr)) {
            str = str.substring(removeBeginStr.length());
        }
        return str;
    }

    /**
     * 首字母小写
     * @param input
     * @return
     */
    public static String firstToLowerCase(String input) {
        if (input == null || input.isEmpty()) {
            return input;
        }
        return Character.toLowerCase(input.charAt(0)) + input.substring(1);
    }
    /**
     * 首字母大写
     * @param input
     * @return
     */
    public static String firstToUpperCase(String input) {
        if (input == null || input.isEmpty()) {
            return input;
        }
        return Character.toUpperCase(input.charAt(0)) + input.substring(1);
    }


}
